package com.example2016.cjj.wxplangamedemo.game;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;

import com.example2016.cjj.wxplangamedemo.view.GameView;

/**
 * Created by CJJ on 2017/3/31.
 *
 * 道具奖品类
 *
 * 运动轨迹：先向下一段距离，在向上回走一段距离，最有加速向下
 */

public class Award extends AutoSprite {
    private static  final int STATUS_DOWN1 = 1;
    private static  final int STATUS_UP2 = 2;
    private static  final int STATUS_DOWN2 = 3;

    private int currentStatus = STATUS_DOWN1;

    public Award(Bitmap bitmap) {
        super(bitmap);
    }


    @Override
    protected void afterDraw(Canvas canvas, Paint paint, GameView gameView) {
        //在afterDraw中不调用super.afterDraw方法，通过自身判断，来销毁
        // super.afterDraw(canvas, paint, gameView);


        float curY = getY(); //获取到当前的y位置

        switch ( currentStatus ){
            case STATUS_DOWN1:
                //先向下一段距离
                if( curY >= canvas.getHeight()*0.25 ){
                    //在到canvas高度的0.25时，改变速率方向，方向：向上
                    setSpeed(-5);
                    currentStatus = STATUS_UP2;
                }
                break;
            case STATUS_UP2:
                //在向上回走一段距离
                if( curY <=5 ){
                    //当回走到5时，改变速率方向，方向：向下
                    setSpeed(13);
                    currentStatus = STATUS_DOWN2;
                }
                break;
            case STATUS_DOWN2:
                //加速向下
                if( curY > canvas.getHeight() ){
                    //超出屏幕高度后，销毁
                    destroy();
                }

                break;
        }




    }


}
